package com.example.demo.service.impl;


import com.example.demo.dao.PhysicalExaminationDao;
import com.example.demo.entity.ExaminationResultEntity;
import com.example.demo.entity.PhysicalExaminationEntity;
import com.example.demo.entity.ResultEntity;
import com.example.demo.result.Result;
import com.example.demo.result.ResultEnum;
import com.example.demo.result.ResultUtil;
import com.example.demo.service.PhysicalExaminationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PhysicalExaminationServiceImpl implements PhysicalExaminationService {

    @Autowired
    private PhysicalExaminationDao physicalExaminationDao;

    @Override
    public Result getMsg(String serialNumber) {
        if (physicalExaminationDao.selectSerialNum(serialNumber) != null){
            PhysicalExaminationEntity physicalExaminationEntity = new PhysicalExaminationEntity();
            ExaminationResultEntity examinationResultEntity =new ExaminationResultEntity();
            ResultEntity resultEntity =  physicalExaminationDao.getMsg(serialNumber);
            physicalExaminationEntity.setAlt(resultEntity.getAlt());
            physicalExaminationEntity.setShit(resultEntity.getShit());
            physicalExaminationEntity.setBlood(resultEntity.getBlood());
            physicalExaminationEntity.setDysentery(resultEntity.getDysentery());
            physicalExaminationEntity.setHavlgM(resultEntity.getHavlgM());
            physicalExaminationEntity.setHevlgM(resultEntity.getHevlgM());
            physicalExaminationEntity.setHealthEdu(resultEntity.getHealthEdu());
            physicalExaminationEntity.setHeart(resultEntity.getHeart());
            physicalExaminationEntity.setLiver(resultEntity.getLiver());
            physicalExaminationEntity.setLung(resultEntity.getLung());
            physicalExaminationEntity.setOtherBody(resultEntity.getOtherBody());
            physicalExaminationEntity.setXrayCheck(resultEntity.getXrayCheck());
            physicalExaminationEntity.setSkin(resultEntity.getSkin());
            physicalExaminationEntity.setSpleen(resultEntity.getSpleen());
            physicalExaminationEntity.setStdCheck(resultEntity.getStdCheck());
            physicalExaminationEntity.setStdHealth(resultEntity.getStdHealth());
            physicalExaminationEntity.setTyphoidfever(resultEntity.getTyphoidfever());
            physicalExaminationEntity.setId(resultEntity.getId());
            examinationResultEntity.setAge(resultEntity.getAge());;
            examinationResultEntity.setCardNumber(resultEntity.getCardNumber());;
            examinationResultEntity.setCompany(resultEntity.getCompany());
            examinationResultEntity.setCompanyAddress(resultEntity.getCompanyAddress());
            examinationResultEntity.setHomeAddress(resultEntity.getHomeAddress());
            examinationResultEntity.setIndustry(resultEntity.getIndustry());
            examinationResultEntity.setPhoneNumber(resultEntity.getPhoneNumber());
            examinationResultEntity.setPhotoUrl(resultEntity.getPhotoUrl());
            examinationResultEntity.setSerialNumber(resultEntity.getSerialNumber());
            examinationResultEntity.setSex(resultEntity.getSex());
            examinationResultEntity.setWorkType(resultEntity.getWorkType());
            examinationResultEntity.setRegisterDate(resultEntity.getRegisterDate());
            examinationResultEntity.setName(resultEntity.getName());
            examinationResultEntity.setId(resultEntity.getId());
            examinationResultEntity.setHealthInfo(physicalExaminationEntity);
            return ResultUtil.success(examinationResultEntity);
        }else {
            return ResultUtil.success(physicalExaminationDao.insertNewResult(serialNumber));
        }

    }

    @Override
    public Result updateResult(PhysicalExaminationEntity physicalExaminationEntity) {
        if(physicalExaminationDao.selectSerialNum(physicalExaminationEntity.getSerialNumber()) != null){
            return ResultUtil.success(physicalExaminationDao.updateResult(physicalExaminationEntity));
        }
        return ResultUtil.success("该编号不存在");
    }

    @Override
    public Result insertNewResult(String serialNumber) {
        if (physicalExaminationDao.selectSerialNum(serialNumber) == null){
            return ResultUtil.success( physicalExaminationDao.insertNewResult(serialNumber));
        }else {
            return ResultUtil.success("请勿重复添加");
        }
    }
}
